package com.example.shishaolong.warehousemanager;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import com.example.shishaolong.warehousemanager.common.DateUtil;
import com.example.shishaolong.warehousemanager.dao.AdminDao;
import com.example.shishaolong.warehousemanager.entity.AdminEntity;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.example.shishaolong.warehousemanager", appContext.getPackageName());
    }

    private Context context;

    @Before
    public void init(){
        context = InstrumentationRegistry.getTargetContext();
    }

    @Test
    public void addAdmin(){
        System.out.println("测试添加管理员");
        AdminDao adminDao = new AdminDao(context);
        AdminEntity adminEntity = new AdminEntity();
        adminEntity.setName("时少龙");
        adminEntity.setPassword("123456");
        adminEntity.setSex(1);
        adminEntity.setLevel(1);
        adminEntity.setAddDate(DateUtil.getCurrentDateStr());
        adminEntity.setModifyDate(DateUtil.getCurrentDateStr());
        adminDao.add(adminEntity);
    }

    @Test
    public void findAllAdmin(){
        System.out.println("测试查询所有的数据");
        AdminDao adminDao = new AdminDao(context);
        List<AdminEntity> adminEntityList = adminDao.findAll();
        for (AdminEntity adminEntity : adminEntityList) {
            System.out.println(adminEntity);
        }
    }

    @Test
    public void deleteAll(){
        System.out.println("测试删除全部开始：");
        AdminDao adminDao = new AdminDao(context);
        adminDao.deleteAll();
    }

    @Test
    public void updateAdmin(){
        System.out.println("测试修改");
        AdminDao adminDao = new AdminDao(context);
        AdminEntity adminEntity = adminDao.findById(7);
        adminEntity.setName("李龙");
        adminDao.update(adminEntity);
    }

    @Test
    public void deleteById(){
        System.out.println("测试删除单个管理员");
        AdminDao adminDao = new AdminDao(context);
        adminDao.delete(6);
    }

}
